#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include <sys/wait.h>

int mysys(char *command)
{
    if(command==NULL)
        return (-1);
    char *word,buffer[100],*argv[20];
    int i=0;
    strcpy(buffer,command);
    word=strtok(buffer," ");
    while(word!=NULL)
    {
        argv[i]=word;
        i++;
        word=strtok(NULL," ");
    }
    argv[i]=NULL;
    pid_t pid;
    int status;
    pid=fork();
    if(pid<0)
    {
        status=-1;
    }
    else if(pid==0)
    {
        int error=execvp(argv[0],argv);
        if(error<0)
        {
            printf("execvp error");
            exit(1);
        }
    }
    else
    {
        wait(&status);
    }
    return status;
}

int main()
{
    printf("---------------------------------------------------------------------------\n");
    mysys("echo HELLO WORLD");
    printf("---------------------------------------------------------------------------\n");
    mysys("ls /");
    printf("---------------------------------------------------------------------------\n");
    return 0;
}
